import 'package:appflutterhomeschool/model/form_switch_model.dart';
import 'package:appflutterhomeschool/model/get_chapter_model.dart';
import 'package:appflutterhomeschool/model/notification_model.dart';
import 'package:appflutterhomeschool/model/questions_model.dart';
import 'package:appflutterhomeschool/model/tab_model.dart';
import 'package:appflutterhomeschool/provider/provider_widget.dart';
import 'package:appflutterhomeschool/res/styles.dart';
import 'package:appflutterhomeschool/ui/widgets/button_widget.dart';
import 'package:appflutterhomeschool/ui/widgets/image_widget.dart';
import 'package:appflutterhomeschool/ui/widgets/notice/form_widget.dart';
import 'package:appflutterhomeschool/ui/widgets/widgets.dart';
import 'package:appflutterhomeschool/utils/letter_display_utils.dart';
import 'package:appflutterhomeschool/utils/utils.dart';
import 'package:appflutterhomeschool/view_model/academic_sentiment/show_chapter_dialog_view_model.dart';
import 'package:appflutterhomeschool/view_model/notice/noticeItem_dialog_view_model.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_cupertino_date_picker/flutter_cupertino_date_picker.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'net_loading_dialog.dart';

///用户：Nine Tailed Fox
///时间：2020/6/9
///邮箱：1037438704@qq.com
///功能：所有的对话框
class PromptDialogWidgets {
  BuildContext me;

  PromptDialogWidgets(this.me);

  static PromptDialogWidgets _promptDialogWidgets;

  static PromptDialogWidgets getPromptDialogWidgets() {
    return _promptDialogWidgets == null
        ? _promptDialogWidgets = PromptDialogWidgets._promptDialogWidgets
        : _promptDialogWidgets;
  }

  //请求对话框
  showLoadingDialog(Function function) {
    showDialog(
        context: me,
        barrierDismissible: false,
        builder: (_) {
          return NetLoadingDialog(
            dismissDialog: function,
            outsideDismiss: false,
          );
        });
  }

  ///单个提示对话框
  showPromptDialog(
      {String title,
      String content,
      String cencel,
      String sure,
      VoidCallback sureOnTap,
      VoidCallback cancelOnTap}) {
    showDialog(
        context: me,
        barrierDismissible: false, //   点击提示框外围不消失
        builder: (BuildContext context) {
          return Scaffold(
            backgroundColor: Colors.transparent,
            body: Column(
              children: <Widget>[
                Expanded(child: Container()),
                Container(
                  decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.circular(10)),
                  width: double.maxFinite,
                  padding: EdgeInsets.all(ScreenUtil().setWidth(69)),
                  margin: EdgeInsets.only(
                      left: ScreenUtil().setWidth(123),
                      right: ScreenUtil().setWidth(123)),
                  child: Column(
                    children: <Widget>[
                      Text(title ?? "温馨提示", style: TextStyles.textDarkBold43),
                      Container(
                        child: Text(content ?? "确定退出当前账号？",
                            style: TextStyles.textDark37),
                        margin: EdgeInsets.only(
                            top: ScreenUtil().setWidth(48),
                            bottom: ScreenUtil().setWidth(87)),
                      ),
                      Row(
                        children: <Widget>[
                          GestureDetector(
                            onTap: () {
                              Navigator.pop(me);
                              if (cancelOnTap != null) {
                                cancelOnTap();
                              }
                            },
                            child: Text(cencel ?? "狠心退出",
                                style: TextStyles.textGray37),
                          ),
                          Expanded(child: Container()),
                          GestureDetector(
                            onTap: () {
                              Navigator.pop(me);
                              if (sureOnTap != null) {
                                sureOnTap();
                              }
                            },
                            child: Text(sure ?? "再逛逛",
                                style: TextStyles.textBlue37),
                          ),
                        ],
                      ),
                    ],
                  ),
                ),
                Expanded(child: Container()),
              ],
            ),
          );
        });
  }

  ///底部弹出对话框
  showButtomDialog(
      {bool identity,
      ValueChanged<ValueModel> onTap,
      List<FormSwitchModel> gridList}) {
    TextEditingController textEditingController = TextEditingController();
    //true 是老师  false 是家长
    String title = "学生信息";
    String content = "你是学生的...";
    if (identity) {
      content = "你的教育目的是...";
      title = "教师信息";
    }
    showModalBottomSheet(
        isScrollControlled: true,
        backgroundColor: Colors.transparent,
        context: me,
        builder: (BuildContext context) {
          return StatefulBuilder(
            builder: (context, setate) {
              return Container(
                padding: EdgeInsets.only(top: ScreenUtil().setWidth(32)),
                decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.only(
                      topLeft: Radius.circular(10),
                      topRight: Radius.circular(10),
                    )),
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  children: <Widget>[
                    Row(
                      children: <Widget>[
                        SizedBox(width: ScreenUtil().setWidth(34)),
                        Expanded(child: Text(title)),
                        IconButton(
                          icon: Icon(
                            Icons.clear,
                            color: Colors.grey,
                          ),
                          onPressed: () => Navigator.pop(context),
                        ),
                        SizedBox(width: ScreenUtil().setWidth(34)),
                      ],
                    ),
                    Visibility(
                      visible: !identity,
                      child: EditWidget(
                          textEditingController: textEditingController,
                          hintText: "学生姓名"),
                    ),
                    Container(
                      alignment: Alignment.centerLeft,
                      margin: EdgeInsets.all(ScreenUtil().setWidth(32)),
                      child: Text(
                        content,
                        style: TextStyles.textDark37,
                      ),
                    ),
                    SizedBox(height: ScreenUtil().setWidth(10)),
                    GridView.builder(
                      shrinkWrap: true,
                      itemCount: gridList.length,
                      physics: NeverScrollableScrollPhysics(),
                      padding: EdgeInsets.symmetric(horizontal: 16),
                      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                        crossAxisCount: identity ? 5 : 4,
                        mainAxisSpacing: 5,
                        crossAxisSpacing: 5,
                        childAspectRatio: 1,
                      ),
                      itemBuilder: (context, index) {
                        return GestureDetector(
                          child: Column(
                            children: <Widget>[
                              gridList[index].fileAndUrl == 1
                                  ? Image.network(
                                      gridList[index].judge
                                          ? gridList[index].imageUrl
                                          : gridList[index].imageUrlFalse,
                                      width: ScreenUtil().setWidth(97),
                                      height: ScreenUtil().setWidth(97),
                                    )
                                  : Image.asset(
                                      Utils.getImgPath(gridList[index].judge
                                          ? gridList[index].imageUrl
                                          : gridList[index].imageUrlFalse),
                                      width: ScreenUtil().setWidth(97),
                                      height: ScreenUtil().setWidth(97),
                                    ),
                              Text(
                                gridList[index].title,
                                style: TextStyles.textDark28,
                              )
                            ],
                          ),
                          onTap: () => setate(() {
                            for (int i = 0; i < gridList.length; i++) {
                              gridList[i].judge = i == index;
                            }
                          }),
                        );
                      },
                    ),
                    SizedBox(height: ScreenUtil().setWidth(10)),
                    GestureDetector(
                        child: Container(
                          width: double.maxFinite,
                          alignment: Alignment.center,
                          height: 45,
                          color: Colors.blue,
                          child: Text("加入班级", style: TextStyles.textWhite37),
                        ),
                        onTap: () {
                          Navigator.pop(context);
                          //调用接口 跳转页面
//                          if (textEditingController.text == "") {
//                            Fluttertoast.showToast(msg: "请输入学生姓名");
//                            return;
//                          }
                          String relationship = "";
                          gridList.forEach((element) {
                            if (element.judge) {
                              relationship = element.title;
                            }
                          });

                          onTap(ValueModel(
                              name: textEditingController.text ?? "",
                              relationship: relationship));
                        })
                  ],
                ),
              );
            },
          );
        });
  }

  ///底部弹出对话框
  showEditDialog(
      {bool identity,
      String bottomName,
      GestureTapCallback onTap,
      TextEditingController textEditing1}) {
    //true 是老师  false 是家长
    String title = "添加学生信息";
    if (identity) {
      title = "请输入班级代码";
    }
    showModalBottomSheet(
        isScrollControlled: true,
        backgroundColor: Colors.transparent,
        context: me,
        builder: (BuildContext context) {
          return StatefulBuilder(
            builder: (context2, state) {
              //需要在脚手架中才能生效
              return Scaffold(
                backgroundColor: Colors.transparent,
                body: GestureDetector(
                  onTap: () => Navigator.pop(context2),
                  child: Container(
                    color: Colors.transparent,
                    child: Stack(
                      children: <Widget>[
                        Positioned(
                          child: Container(
                            padding:
                                EdgeInsets.only(top: ScreenUtil().setWidth(32)),
                            decoration: BoxDecoration(
                                color: Colors.white,
                                borderRadius: BorderRadius.only(
                                  topLeft: Radius.circular(10),
                                  topRight: Radius.circular(10),
                                )),
                            child: Column(
                              mainAxisSize: MainAxisSize.min,
                              children: <Widget>[
                                Row(
                                  children: <Widget>[
                                    SizedBox(width: ScreenUtil().setWidth(34)),
                                    Expanded(child: Text(title)),
                                    IconButton(
                                      icon: Icon(
                                        Icons.clear,
                                        color: Colors.grey,
                                      ),
                                      onPressed: () => Navigator.pop(context),
                                    ),
                                    SizedBox(width: ScreenUtil().setWidth(34)),
                                  ],
                                ),
                                EditWidget(
                                    textEditingController: textEditing1,
                                    hintText: "请输入班级代码"),
                                SizedBox(height: ScreenUtil().setWidth(10)),
                                GestureDetector(
                                  child: Container(
                                    width: double.maxFinite,
                                    alignment: Alignment.center,
                                    height: 45,
                                    color: Colors.blue,
                                    child: Text(
                                      "下一步",
                                      style: TextStyles.textWhite37,
                                    ),
                                  ),
                                  onTap: () {
                                    Navigator.pop(context);
                                    if (onTap != null) {
                                      onTap();
                                    }
                                  },
                                )
                              ],
                            ),
                          ),
                          //这里需要获取键盘的高度
                          bottom: MediaQuery.of(context).viewInsets.bottom > 0
                              ? 0
                              : MediaQuery.of(context)
                                  .viewInsets
                                  .bottom, //300换成键盘高度值效果更好
                          left: 0,
                          right: 0,
                        )
                      ],
                    ),
                  ),
                ),
              );
            },
          );
        });
  }

  ///底部弹出对话框
  ///pageTage 0是通知文  1是表单
  noticeItemButtomDialog(
      {int pageTag, NotificationModel notificationModel, VoidCallback onTap}) {
    showModalBottomSheet(
        backgroundColor: Colors.transparent,
        context: me,
        isScrollControlled: true,
        builder: (BuildContext context) {
          return StatefulBuilder(
            builder: (context2, child) {
              return Scaffold(
                resizeToAvoidBottomPadding: true, //输入框抵住键盘
                backgroundColor: Colors.transparent,
                body: ProviderWidget<NoticeltemDialogViewModel>(
                  model: NoticeltemDialogViewModel(context2, notificationModel),
                  onModelReady: (value) => value.initView(),
                  builder: (context, viewModel, child) {
                    return Column(
                      children: [
                        Expanded(
                          child: GestureDetector(
                            child: Container(
                              color: Colors.transparent,
                            ),
                            onTap: () => Navigator.pop(context),
                          ),
                        ),
                        Expanded(
                          flex: 4,
                          child: Container(
                            decoration: BoxDecoration(
                                color: Colors.white,
                                borderRadius: BorderRadius.only(
                                  topLeft: Radius.circular(10),
                                  topRight: Radius.circular(10),
                                )),
                            child: Stack(
                              children: <Widget>[
                                Positioned(
                                  left: 0,
                                  right: 0,
                                  top: 0,
                                  bottom:
                                      MediaQuery.of(context).viewInsets.bottom >
                                              0
                                          ? 0
                                          : MediaQuery.of(context)
                                              .viewInsets
                                              .bottom,
                                  child: Padding(
                                    padding: EdgeInsets.only(
                                      left: ScreenUtil().setWidth(35),
                                      right: ScreenUtil().setWidth(35),
                                      top: ScreenUtil().setWidth(35),
                                    ),
                                    child: Column(
                                      mainAxisAlignment:
                                          MainAxisAlignment.start,
                                      crossAxisAlignment:
                                          CrossAxisAlignment.start,
                                      children: <Widget>[
                                        //基础信息展示
                                        Container(
                                          padding: EdgeInsets.only(
                                              bottom:
                                                  ScreenUtil().setWidth(70)),
                                          child: Row(
                                            mainAxisAlignment:
                                                MainAxisAlignment.start,
                                            crossAxisAlignment:
                                                CrossAxisAlignment.start,
                                            children: <Widget>[
                                              //头像展示
                                              ImageWidget(
                                                  imageUrl: viewModel
                                                          ?.notification
                                                          ?.senderImg ??
                                                      ""),
                                              SizedBox(
                                                  width: ScreenUtil()
                                                      .setWidth(26)),
                                              Expanded(
                                                  child: Column(
                                                mainAxisAlignment:
                                                    MainAxisAlignment.start,
                                                crossAxisAlignment:
                                                    CrossAxisAlignment.start,
                                                children: <Widget>[
                                                  Text.rich(TextSpan(children: [
                                                    TextSpan(
                                                        text: LetterDisplayUtils
                                                                .maxLength(viewModel
                                                                    ?.notification
                                                                    ?.senderName) ??
                                                            "昵称",
                                                        style: TextStyles
                                                            .textDark31),
                                                    TextSpan(
                                                        text:
                                                            "\t\t${notificationModel.notificationCls}\t\t${notificationModel.datetime}",
                                                        style: TextStyles
                                                            .textGray30),
                                                  ])),
                                                  SizedBox(
                                                      height: ScreenUtil()
                                                          .setWidth(43)),
                                                  Text("发至我",
                                                      style: TextStyles
                                                          .textGray30),
                                                  SizedBox(
                                                      height: ScreenUtil()
                                                          .setWidth(43)),
                                                  Visibility(
                                                    child: Text.rich(
                                                      TextSpan(children: [
                                                        TextSpan(
                                                          text:
                                                              "${notificationModel?.write ?? 0}人已确认",
                                                          style: TextStyles
                                                              .textBlue30,
                                                          recognizer: viewModel
                                                              .gestureOnTap1,
                                                        ),

                                                        /// 灰色图标  gengduo_hui
                                                        WidgetSpan(
                                                          child: Container(
                                                            child: Image.asset(
                                                                Utils.getImgPath(
                                                                    "gengduo_hui")),
                                                            padding:
                                                                EdgeInsets.only(
                                                                    bottom: 5),
                                                          ),
                                                        ),
                                                        TextSpan(
                                                          text:
                                                              "·\t\t${viewModel?.notification?.noRead ?? 0}人未读",
                                                          style: TextStyles
                                                              .textBlue30,
                                                          recognizer: viewModel
                                                              .gestureOnTap2,
                                                        ),
                                                        WidgetSpan(
                                                          child: Container(
                                                            child: Image.asset(
                                                                Utils.getImgPath(
                                                                    "gengduo_lan")),
                                                            padding:
                                                                EdgeInsets.only(
                                                                    bottom: 5),
                                                          ),
                                                        ),
                                                      ]),
                                                    ),
                                                    visible: viewModel.identity,
                                                  ),
                                                ],
                                              )),
                                            ],
                                          ),
                                        ),
                                        //这个是表单
                                        Expanded(
                                          child: SingleChildScrollView(
                                            child: pageTag == 0 || pageTag == 1
                                                ? Column(
                                                    crossAxisAlignment:
                                                        CrossAxisAlignment
                                                            .start,
                                                    mainAxisAlignment:
                                                        MainAxisAlignment.start,
                                                    children: <Widget>[
                                                      Text(
                                                        viewModel?.notification
                                                                ?.title ??
                                                            "",
                                                        style: TextStyles
                                                            .textDarkBold43,
                                                      ),
                                                      Text(
                                                        viewModel?.notification
                                                                ?.msg ??
                                                            "",
                                                        style: TextStyles
                                                            .textDark37,
                                                      ),
                                                      //列表数据
                                                      Visibility(
                                                        child: ListViewWidget(
                                                          shanchuFujian: false,
                                                          listImage: viewModel
                                                                  .notification
                                                                  ?.img ??
                                                              [],
                                                        ),
                                                        visible: viewModel
                                                                    .notification
                                                                    ?.img !=
                                                                null ||
                                                            (viewModel
                                                                        .notification
                                                                        ?.img
                                                                        ?.length ??
                                                                    0) !=
                                                                0,
                                                      ),
                                                      SizedBox(
                                                          height: ScreenUtil()
                                                              .setWidth(114))
                                                    ],
                                                  )
                                                : Column(
                                                    mainAxisAlignment:
                                                        MainAxisAlignment.start,
                                                    crossAxisAlignment:
                                                        CrossAxisAlignment
                                                            .start,
                                                    children: <Widget>[
                                                      viewModel.listQuestions !=
                                                              null
                                                          ? ListView.builder(
                                                              shrinkWrap: true,
                                                              physics:
                                                                  NeverScrollableScrollPhysics(),
                                                              itemCount: viewModel
                                                                  .listQuestions
                                                                  .length,
                                                              itemBuilder:
                                                                  (context,
                                                                      index) {
                                                                QuestionsModel
                                                                    questionsModel =
                                                                    viewModel
                                                                            .listQuestions[
                                                                        index];
                                                                List<Options>
                                                                    optionsList =
                                                                    questionsModel
                                                                        .options;
                                                                return Column(
                                                                    children: [
                                                                      Padding(
                                                                        padding: EdgeInsets.only(
                                                                            top:
                                                                                ScreenUtil().setWidth(34),
                                                                            bottom: ScreenUtil().setWidth(34)),
                                                                        child:
                                                                            TitleMenuWidget(
                                                                          titleContext:
                                                                              questionsModel.body,
                                                                          visibleDelete:
                                                                              false,
                                                                        ),
                                                                      ),
                                                                      Padding(
                                                                        padding: EdgeInsets.only(
                                                                            top:
                                                                                ScreenUtil().setWidth(34),
                                                                            bottom: ScreenUtil().setWidth(34)),
                                                                        child: questionsModel.questionType ==
                                                                                "SC"
                                                                            ? SingleChoiceWidget(
                                                                                optionsList: optionsList,
                                                                                onTapIndex: (optionIndex) {
                                                                                  viewModel.radiClick(index, optionIndex);
                                                                                },
                                                                              )
                                                                            : (questionsModel.questionType == "MC"
                                                                                ? MultipleChoiceWidget(
                                                                                    optionsList: optionsList,
                                                                                    onTapIndex: (optionIndex) {
                                                                                      viewModel.multipleChoice(index, optionIndex);
                                                                                    },
                                                                                  )
                                                                                : (questionsModel.questionType == "C"
                                                                                    ? FormTextWidget(
                                                                                        textEditingController: questionsModel.questionText,
                                                                                        enabled: true,
                                                                                      )
                                                                                    : Container())),
                                                                      )
                                                                    ]);
                                                              })
                                                          : Container(),
                                                      ButtonWidget()
                                                          .rectangleButtonWidget(
                                                              buttonName: "提交",
                                                              onPressed: viewModel
                                                                  .desposeFormAnswerOnTap),
                                                    ],
                                                  ),
                                          ),
                                        ),
                                      ],
                                    ),
                                  ),
                                ),
                                Positioned(
                                    right: ScreenUtil().setWidth(10),
                                    top: 0,
                                    child: IconButton(
                                      icon: Icon(
                                        Icons.clear,
                                        color: Colors.grey,
                                      ),
                                      onPressed: () {
                                        if (onTap != null) {
                                          onTap();
                                        }
                                        Navigator.pop(context);
                                      },
                                    )),
                                Positioned(
                                  bottom: 0,
                                  left: 0,
                                  right: 0,
                                  child: Visibility(
                                    visible:
                                        !viewModel.identity && pageTag != 2 ??
                                            false,
                                    child: GestureDetector(
                                      child: Container(
                                        alignment: Alignment.center,
                                        height: ScreenUtil().setWidth(114),
                                        color: viewModel
                                                    ?.notification?.confirmed ??
                                                true
                                            ? Colors.blue
                                            : Colors.white,
                                        child: Text(
                                          viewModel?.notification?.confirmed ??
                                                  true
                                              ? "确认收到"
                                              : "已确认",
                                          style: viewModel?.notification
                                                      ?.confirmed ??
                                                  true
                                              ? TextStyles.textWhite30
                                              : TextStyles.textDark30,
                                        ),
                                      ),
                                      onTap: () {
                                        onTap();
                                        viewModel.sureReedOnTap();
                                      },
                                    ),
                                  ),
                                )
                              ],
                            ),
                          ),
                        )
                      ],
                    );
                  },
                ),
              );
            },
          );
        });
  }

  ///底部弹出时间选择 时分秒
  dateButtomDialog({DateTime dateTime, ValueChanged<DateTime> onConfirm}) {
    DatePicker.showDatePicker(me,
        pickerTheme: DateTimePickerTheme(
          showTitle: true,
          confirm: Text('确定', style: TextStyle(color: Colors.blue)),
          cancel: Text('取消', style: TextStyle(color: Colors.grey)),
        ),
        minDateTime: DateTime.parse("${dateTime.year}-01-01"),
        maxDateTime: DateTime.parse("${dateTime.year}-12-31"),
        initialDateTime: dateTime,
        // dateFormat: "yyyy-MMMM-dd", //只包含年、月、日
        dateFormat: "M月d日  EEE,H时:m分",
        pickerMode: DateTimePickerMode.time,
        locale: DateTimePickerLocale.zh_cn, onCancel: () {
      debugPrint("onCancel");
    }, onConfirm: (dateTime, List<int> index) {
      onConfirm(dateTime);
    });
  }

  ///拒绝底部弹框
  refuseButtomDialog({GestureTapCallback onTap}) {
    showModalBottomSheet(
        backgroundColor: Colors.transparent,
        context: me,
        isScrollControlled: true,
        builder: (BuildContext context) {
          return StatefulBuilder(
            builder: (context2, state) {
              //需要在脚手架中才能生效
              return Scaffold(
                backgroundColor: Colors.transparent,
                body: GestureDetector(
                  onTap: () => Navigator.pop(context2),
                  child: Container(
                    color: Colors.transparent,
                    child: Stack(
                      children: <Widget>[
                        Positioned(
                          child: Container(
                              color: Colors.white,
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.end,
                                mainAxisAlignment: MainAxisAlignment.end,
                                children: <Widget>[
                                  Row(
                                    children: <Widget>[
                                      Padding(
                                          padding: EdgeInsets.only(
                                              left: ScreenUtil().setWidth(33)),
                                          child: Text("拒绝原因")),
                                      Expanded(child: Container()),
                                      IconButton(
                                        icon: Icon(Icons.clear,
                                            color: Colors.grey),
                                        onPressed: () {
                                          Navigator.pop(context);
                                        },
                                      ),
                                    ],
                                  ),
                                  Container(
                                    height: ScreenUtil().setWidth(526),
                                    child: TextField(
                                      // controller: textEditingController,
                                      //是否隐藏密码
                                      obscureText: false,
                                      //绑定焦点控制
                                      // focusNode: nodeOne,
                                      // textCapitalization: TextCapitalization.sentences,
                                      //控制光标样式
                                      cursorColor: Colors.black,
                                      // cursorRadius: Radius.circular(6.0),
                                      cursorWidth: 2.0,
                                      //自动获取焦点
                                      autofocus: true,
                                      //最大长度，设置此项会让TextField右下角有一个输入数量的统计字符串
                                      // maxLength: 1130,
                                      //输入文本的样式
                                      style: TextStyle(
                                          fontSize: 15.0, color: Colors.black),
                                      keyboardType: TextInputType.text,
                                      //键盘回车键的样式
                                      textInputAction: TextInputAction.send,
                                      //内容改变的回调
                                      onChanged: (text) {
                                        state(() {});
                                      },
                                      decoration: InputDecoration(
                                        hintText: "",
                                        hintStyle: TextStyle(
                                            fontWeight: FontWeight.w300,
                                            color: Colors.grey),
                                        //填充颜色
                                        fillColor: Colors.white,
                                        filled: true,
                                        border: InputBorder.none,
                                        // 去掉下滑线
                                        counterText: '',
                                        // 边框的内边距
                                        contentPadding: EdgeInsets.only(
                                            left: ScreenUtil().setWidth(33),
                                            right: ScreenUtil().setWidth(33),
                                            bottom: 10),
                                      ),
                                    ),
                                  ),
                                  GestureDetector(
                                    child: Container(
                                      alignment: Alignment.center,
                                      height: ScreenUtil().setWidth(114),
                                      color: Colors.blue,
                                      child: Text("确认拒绝",
                                          style: TextStyles.textWhite37),
                                    ),
                                    onTap: () {
                                      Navigator.pop(context);
                                      onTap();
                                    },
                                  ),
                                ],
                              )),
                          //这里需要获取键盘的高度
                          bottom: MediaQuery.of(context).viewInsets.bottom > 0
                              ? 0
                              : MediaQuery.of(context)
                                  .viewInsets
                                  .bottom, //300换成键盘高度值效果更好
                          left: 0,
                          right: 0,
                        )
                      ],
                    ),
                  ),
                ),
              );
            },
          );
        });
  }

  ///底部弹出对话框
  newIdentityDialog({
    bool identity,
    String bottomName,
    GestureTapCallback onTap,
    TextEditingController textEditingController,
    TextEditingController textEditingController2,
  }) {
    //true 是老师  false 是家长
    String title = "";
    if (identity) {
      title = "教师姓名";
    } else {
      title = "家长姓名";
    }
    showModalBottomSheet(
        isScrollControlled: true,
        backgroundColor: Colors.transparent,
        context: me,
        builder: (BuildContext context) {
          return StatefulBuilder(
            builder: (context2, state) {
              //需要在脚手架中才能生效
              return Scaffold(
                backgroundColor: Colors.transparent,
                body: GestureDetector(
                  onTap: () => Navigator.pop(context2),
                  child: Container(
                    color: Colors.transparent,
                    child: Stack(
                      children: <Widget>[
                        Positioned(
                          child: Container(
                            padding:
                                EdgeInsets.only(top: ScreenUtil().setWidth(32)),
                            decoration: BoxDecoration(
                                color: Colors.white,
                                borderRadius: BorderRadius.only(
                                  topLeft: Radius.circular(10),
                                  topRight: Radius.circular(10),
                                )),
                            child: Column(
                              mainAxisSize: MainAxisSize.min,
                              children: <Widget>[
                                Row(
                                  children: <Widget>[
                                    SizedBox(width: ScreenUtil().setWidth(34)),
                                    Expanded(child: Text(title)),
                                    IconButton(
                                      icon: Icon(
                                        Icons.clear,
                                        color: Colors.grey,
                                      ),
                                      onPressed: () => Navigator.pop(context),
                                    ),
                                    SizedBox(width: ScreenUtil().setWidth(34)),
                                  ],
                                ),
                                EditWidget(
                                    textEditingController:
                                        textEditingController,
                                    hintText: "请输入昵称"),
                                Visibility(
                                  visible: identity,
                                  child: EditWidget(
                                      textEditingController:
                                          textEditingController2,
                                      hintText: "请输入学校名称"),
                                ),
                                SizedBox(height: ScreenUtil().setWidth(10)),
                                GestureDetector(
                                  child: Container(
                                    width: double.maxFinite,
                                    alignment: Alignment.center,
                                    height: 45,
                                    color: Colors.blue,
                                    child: Text(
                                      "确定",
                                      style: TextStyles.textWhite37,
                                    ),
                                  ),
                                  onTap: () {
                                    Navigator.pop(context);
                                    if (onTap != null) {
                                      onTap();
                                    }
                                  },
                                )
                              ],
                            ),
                          ),
                          //这里需要获取键盘的高度
                          bottom: MediaQuery.of(context).viewInsets.bottom > 0
                              ? 0
                              : MediaQuery.of(context)
                                  .viewInsets
                                  .bottom, //300换成键盘高度值效果更好
                          left: 0,
                          right: 0,
                        )
                      ],
                    ),
                  ),
                ),
              );
            },
          );
        });
  }

  ///添加题目   表单页面
  formSwitchButtomDialog({ValueChanged<int> valueChanged}) {
    showModalBottomSheet(
        isScrollControlled: true,
        backgroundColor: Colors.transparent,
        context: me,
        builder: (BuildContext context) {
          return Container(
            padding: EdgeInsets.only(top: ScreenUtil().setWidth(32)),
            decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.only(
                  topLeft: Radius.circular(10),
                  topRight: Radius.circular(10),
                )),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: <Widget>[
                Row(
                  children: <Widget>[
                    SizedBox(width: ScreenUtil().setWidth(34)),
                    Expanded(child: Text("添加题型", style: TextStyles.textDark43)),
                    IconButton(
                      icon: Icon(Icons.clear, color: Colors.grey),
                      onPressed: () => Navigator.pop(context),
                    ),
                    SizedBox(width: ScreenUtil().setWidth(34)),
                  ],
                ),
                SizedBox(height: ScreenUtil().setWidth(34)),
                GridView.builder(
                  shrinkWrap: true,
                  itemCount: listFormSwitchModel.length,
                  physics: NeverScrollableScrollPhysics(),
                  padding: EdgeInsets.symmetric(horizontal: 16),
                  gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                    crossAxisCount: 4,
                    mainAxisSpacing: 5,
                    crossAxisSpacing: 5,
                    childAspectRatio: 1,
                  ),
                  itemBuilder: (context, index) {
                    return GestureDetector(
                      child: Column(
                        children: <Widget>[
                          Image.asset(
                            Utils.getImgPath(
                                listFormSwitchModel[index].imageUrl),
                            width: ScreenUtil().setWidth(97),
                            height: ScreenUtil().setWidth(97),
                          ),
                          Padding(
                            padding: EdgeInsets.only(top: 5),
                            child: Text(
                              listFormSwitchModel[index].title,
                              style: TextStyles.textDark30,
                            ),
                          )
                        ],
                      ),
                      onTap: () {
                        Navigator.pop(context);
                        valueChanged(index);
                      },
                    );
                  },
                ),
              ],
            ),
          );
        });
  }

  //相机调用
  showaFileDialog({ValueChanged<int> getIndex}) {
    List list = [
      "拍照",
      "相册",
      "取消",
    ];
    showModalBottomSheet(
        isScrollControlled: true,
        backgroundColor: Colors.transparent,
        context: me,
        builder: (BuildContext context) {
          return Container(
            decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.only(
                  topLeft: Radius.circular(10),
                  topRight: Radius.circular(10),
                )),
            child: ListView.builder(
                shrinkWrap: true,
                itemCount: list.length,
                itemBuilder: (context, index) {
                  return GestureDetector(
                    child: Container(
                      color: Colors.transparent,
                      child: Column(
                        children: [
                          Container(
                            alignment: Alignment.center,
                            padding: EdgeInsets.all(ScreenUtil().setWidth(34)),
                            child: Text(list[index]),
                          ),
                          Visibility(
                            visible: index != 3,
                            child: Container(
                              height: 0.5,
                              color: Colors.grey[200],
                            ),
                          ),
                        ],
                      ),
                    ),
                    onTap: () {
                      Navigator.pop(me);
                      getIndex(index);
                    },
                  );
                }),
          );
        });
  }

  //选择章节
  showChapterDialog(List<ChapteModel> chapteModel,
      {ValueChanged<List<ChapteModel>> valueChanged}) {
    showModalBottomSheet(
        backgroundColor: Colors.transparent,
        context: me,
        isScrollControlled: true,
        builder: (BuildContext context) {
          return ProviderWidget<ShowChapterDialogViewModel>(
            model: ShowChapterDialogViewModel(context, chapteModel),
            onModelReady: (value) => value.initView(),
            builder: (context, viewModel, child) {
              return Container(
                height: ScreenUtil().setWidth(1183),
                decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.only(
                      topLeft: Radius.circular(10),
                      topRight: Radius.circular(10),
                    )),
                child: Column(
                  children: [
                    Row(
                      children: [
                        SizedBox(width: ScreenUtil().setWidth(34)),
                        Expanded(
                            child:
                                Text("作业范围", style: TextStyles.textDarkBold43)),
                        IconButton(
                          icon: Icon(
                            Icons.clear,
                            color: Colors.grey,
                          ),
                          onPressed: () {
                            Navigator.pop(context);
                          },
                        )
                      ],
                    ),
                    Container(
                      padding: EdgeInsets.only(left: 5),
                      alignment: Alignment.centerLeft,
                      child: ListView.builder(
                          scrollDirection: Axis.horizontal,
                          shrinkWrap: true,
                          itemCount: viewModel.titleContent?.length,
                          itemBuilder: (context, index) {
                            String nameContent;
                            if (viewModel.titleContent[index].name == null) {
                              nameContent = "请选择";
                            } else {
                              nameContent =
                                  "${viewModel.titleContent[index].order}\t${viewModel.titleContent[index].name}";
                            }
                            return GestureDetector(
                              onTap: () => viewModel.selectOnTap(index),
                              child: Visibility(
                                child: Container(
                                  margin: EdgeInsets.only(right: 10),
                                  height: 30,
                                  child: Column(
                                    crossAxisAlignment:
                                        CrossAxisAlignment.center,
                                    mainAxisAlignment: MainAxisAlignment.center,
                                    children: [
                                      Text(nameContent,
                                          style: viewModel
                                                  .titleContent[index].select
                                              ? TextStyles.textBlue37
                                              : TextStyles.textDark37),
                                      Spacer(),
                                      Visibility(
                                        visible: viewModel
                                                .titleContent[index].select ??
                                            true,
                                        child: Container(
                                          color: Colors.blue,
                                          width: 10,
                                          height: 3,
                                        ),
                                      )
                                    ],
                                  ),
                                ),
                                visible: viewModel?.titleContent[index]?.choice,
                              ),
                            );
                          }),
                      height: 30,
                    ),
                    Visibility(
                      visible: viewModel.listBool,
                      child: Expanded(
                        child: viewModel.listGetChapterModel == null
                            ? Container()
                            : ListView.builder(
                                shrinkWrap: true,
                                itemCount: viewModel.listGetChapterModel.length,
                                itemBuilder: (context, index) {
                                  String nameContent =
                                      "${viewModel.listGetChapterModel[index].order}\t${viewModel.listGetChapterModel[index].name}";
                                  return GestureDetector(
                                    child: Container(
                                      padding: EdgeInsets.only(
                                          top: ScreenUtil().setWidth(34),
                                          left: ScreenUtil().setWidth(34)),
                                      child: Text(nameContent),
                                    ),
                                    onTap: () => viewModel.chapterOnTap(index),
                                  );
                                }),
                      ),
                    ),
                    Visibility(
                      visible: !viewModel.listBool,
                      child: Expanded(
                        child: viewModel.sections == null
                            ? Container()
                            : ListView.builder(
                                shrinkWrap: true,
                                itemCount: viewModel.sections.length,
                                itemBuilder: (context, index) {
                                  String nameContent =
                                      "${viewModel.sections[index].order}\t${viewModel.sections[index].name}";
                                  return GestureDetector(
                                    child: Container(
                                      padding: EdgeInsets.only(
                                          top: ScreenUtil().setWidth(34),
                                          left: ScreenUtil().setWidth(34)),
                                      child: Text(nameContent),
                                    ),
                                    onTap: () {
                                      viewModel.sectionsOnTap(index);
                                      if (valueChanged != null) {
                                        valueChanged(viewModel.titleContent);
                                      }
                                    },
                                  );
                                }),
                      ),
                    ),
                  ],
                ),
              );
            },
          );
        });
  }

  //评论
  commentDialog(
      {ValueChanged<CommondModel> dahuiOnTap,
      ValueChanged<CommondModel> sureOnTap}) {
    TextEditingController textEditingController = TextEditingController();
    List<bool> listBoolModel = [
      true,
      true,
      true,
      true,
      true,
    ];
    showModalBottomSheet(
        isScrollControlled: true,
        backgroundColor: Colors.transparent,
        context: me,
        builder: (BuildContext context) {
          return StatefulBuilder(
            builder: (context2, state) {
              //需要在脚手架中才能生效
              return Scaffold(
                backgroundColor: Colors.transparent,
                body: GestureDetector(
                  onTap: () => Navigator.pop(context2),
                  child: Container(
                    color: Colors.transparent,
                    child: Stack(
                      children: <Widget>[
                        Positioned(
                          child: Container(
                            padding:
                                EdgeInsets.only(top: ScreenUtil().setWidth(32)),
                            decoration: BoxDecoration(
                                color: Colors.white,
                                borderRadius: BorderRadius.only(
                                  topLeft: Radius.circular(10),
                                  topRight: Radius.circular(10),
                                )),
                            child: Column(
                              mainAxisSize: MainAxisSize.min,
                              children: <Widget>[
                                Row(
                                  children: <Widget>[
                                    Padding(
                                        padding: EdgeInsets.only(
                                            left: ScreenUtil().setWidth(33)),
                                        child: Text("批改作业")),
                                    Expanded(child: Container()),
                                    IconButton(
                                      icon:
                                          Icon(Icons.clear, color: Colors.grey),
                                      onPressed: () {
                                        Navigator.pop(context);
                                      },
                                    ),
                                  ],
                                ),
                                Container(
                                  height: 40,
                                  child: ListView.builder(
                                      scrollDirection: Axis.horizontal,
                                      physics: NeverScrollableScrollPhysics(),
                                      shrinkWrap: true,
                                      itemCount: listBoolModel.length,
                                      itemBuilder: (context, index) {
                                        return GestureDetector(
                                          child: Icon(Icons.star,
                                              size: 30,
                                              color: listBoolModel[index]
                                                  ? Colors.red
                                                  : Colors.grey[200]),
                                          onTap: () {
                                            state(() {
                                              for (int i = 0;
                                                  i < listBoolModel.length;
                                                  i++) {
                                                listBoolModel[i] = false;
                                              }
                                              for (int i = 0;
                                                  i < index + 1;
                                                  i++) {
                                                listBoolModel[i] = true;
                                              }
                                            });
                                          },
                                        );
                                      }),
                                ),
                                Padding(
                                  padding:
                                      EdgeInsets.all(ScreenUtil().setWidth(34)),
                                  child: Material(
                                    borderRadius:
                                        BorderRadius.all(Radius.circular(5)),
                                    elevation: 4.0,
                                    child: Container(
                                      height: ScreenUtil().setWidth(526),
                                      child: TextField(
                                        controller: textEditingController,
                                        cursorColor: Colors.black,
                                        // cursorRadius: Radius.circular(6.0),
                                        cursorWidth: 2.0,
                                        //自动获取焦点
                                        autofocus: true,
                                        style: TextStyle(
                                            fontSize: 15.0,
                                            color: Colors.black),
                                        keyboardType: TextInputType.text,
                                        //键盘回车键的样式
                                        textInputAction: TextInputAction.send,
                                        //内容改变的回调
                                        onChanged: (text) {},
                                        decoration: InputDecoration(
                                          hintText: "",
                                          hintStyle: TextStyle(
                                              fontWeight: FontWeight.w300,
                                              color: Colors.grey),
                                          //填充颜色
                                          fillColor: Colors.white,
                                          filled: true,
                                          border: InputBorder.none,
                                          // 去掉下滑线
                                          counterText: '',
                                          // 边框的内边距
                                          contentPadding: EdgeInsets.only(
                                              left: ScreenUtil().setWidth(33),
                                              right: ScreenUtil().setWidth(33),
                                              bottom: 10),
                                        ),
                                      ),
                                    ),
                                  ),
                                ),
                                Container(
                                  child: Row(
                                    children: [
                                      Expanded(
                                        child: ButtonWidget()
                                            .rectangleButtonWidget(
                                                buttonName: "打回",
                                                textStyle:
                                                    TextStyles.textDark37,
                                                bgColor: Colors.white,
                                                onPressed: () {
                                                  Navigator.pop(context);

                                                  if (textEditingController
                                                          .text ==
                                                      "") {
                                                    return;
                                                  }
                                                  int count = 0;
                                                  listBoolModel
                                                      .forEach((element) {
                                                    if (element) {
                                                      count++;
                                                    }
                                                  });
                                                  if (dahuiOnTap != null) {
                                                    dahuiOnTap(CommondModel(
                                                        msg:
                                                            textEditingController
                                                                .text,
                                                        count: count));
                                                  }
                                                }),
                                      ),
                                      Expanded(
                                        child: ButtonWidget()
                                            .rectangleButtonWidget(
                                                buttonName: "提交",
                                                onPressed: () {
                                                  Navigator.pop(context);

                                                  if (textEditingController
                                                          .text ==
                                                      "") {
                                                    return;
                                                  }
                                                  int count = 0;
                                                  listBoolModel
                                                      .forEach((element) {
                                                    if (element) {
                                                      count++;
                                                    }
                                                  });
                                                  if (sureOnTap != null) {
                                                    sureOnTap(CommondModel(
                                                        msg:
                                                            textEditingController
                                                                .text,
                                                        count: count));
                                                  }
                                                }),
                                      ),
                                    ],
                                  ),
                                )
                              ],
                            ),
                          ),
                          //这里需要获取键盘的高度
                          bottom: MediaQuery.of(context).viewInsets.bottom > 0
                              ? 0
                              : MediaQuery.of(context)
                                  .viewInsets
                                  .bottom, //300换成键盘高度值效果更好
                          left: 0,
                          right: 0,
                        )
                      ],
                    ),
                  ),
                ),
              );
            },
          );
        });
  }
}
